package P3排序算法;

/*
01完全随机：选择>冒泡>插入>希尔≈归并≈堆≈快排
02大致升序：冒泡>选择>快排≈堆>希尔>插入≈归并
03大致降序：选择>冒泡>插入>希尔≈快排≈归并≈堆
04大致相等：冒泡>选择>希尔≈堆>插入≈归并≈快排
*/
public class TestSort {
    public static void main(String[] args) {
        int[] arr = DataUtil.getData04();
        //选择排序
        test01("选择排序", DataUtil.copy(arr));
        //冒泡排序
        test02("冒泡排序", DataUtil.copy(arr));
        //插入排序
        test03("插入排序", DataUtil.copy(arr));
        //希尔排序
        test04("希尔排序", DataUtil.copy(arr));
        //归并排序
        test05("归并排序", DataUtil.copy(arr));
        //堆排序
        test06("堆排序", DataUtil.copy(arr));
        //快速排序
        test07("快速排序", DataUtil.copy(arr));
    }

    private static void test01(String name, int[] arr) {
        System.out.print(name + ":");
        long startTime = System.currentTimeMillis();
        SelectionSort.sort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - startTime + "ms");
    }

    private static void test02(String name, int[] arr) {
        System.out.print(name + ":");
        long startTime = System.currentTimeMillis();
        BubbleSort.sort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - startTime + "ms");
    }

    private static void test03(String name, int[] arr) {
        System.out.print(name + ":");
        long startTime = System.currentTimeMillis();
        InsertionSort.sort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - startTime + "ms");
    }

    private static void test04(String name, int[] arr) {
        System.out.print(name + ":");
        long startTime = System.currentTimeMillis();
        ShellSort.sort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - startTime + "ms");
    }

    private static void test05(String name, int[] arr) {
        System.out.print(name + ":");
        long startTime = System.currentTimeMillis();
        MergeSort.sort(arr, 0, arr.length - 1);
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - startTime + "ms");
    }

    private static void test06(String name, int[] arr) {
        System.out.print(name + ":");
        long startTime = System.currentTimeMillis();
        HeapSort.sort(arr);
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - startTime + "ms");
    }

    private static void test07(String name, int[] arr) {
        System.out.print(name + ":");
        long startTime = System.currentTimeMillis();
        QuickSort.sort(arr, 0, arr.length - 1);
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - startTime + "ms");
    }
}
